package net.neptech.feign.config;

import feign.RequestInterceptor;
import lombok.extern.slf4j.Slf4j;
import net.neptech.utils.SecurityUtils;
import net.neptech.vm.constant.SecurityConstants;
import org.apache.http.HttpHeaders;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Author: liyuxiang
 * @Date: 2025/8/15 20:27
 * @Description: TODO
 */
@Configuration
@Slf4j
public class FeignConfig {
    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            template.header(SecurityConstants.INNER, "true");
            var attrs = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            if (attrs != null && attrs.getRequest() != null) {
                log.info("OpenFeign携带token：{}", SecurityUtils.getToken());
                template.header("Authorization", "Bearer " + SecurityUtils.getToken());
            }
        };
    }
}
